/**
 * 基本药物弹窗模块，点击图表首页后初始化弹窗数据
 * 
 * @Date: 2016-1-25
 * @author: Jackson wang
 * @version: 1.0
 * @since: 1.0
 */

define(["jquery","sysmanMain","valueUtil","panelUtil","btnServ","datagridServ"],
		function($,sysmanMain,valueUtil,panelUtil,btnServ,datagridServ) {

		var rootid = 'panel-anti-medical';
		
		var window_id = 'anti-medical-pop-win';
		
		var module_code ='antiMedicalInfo';
		
		//门诊或住院类型定义
		var queryParam 
		var _buttonConfig;
		var public_method = {
			openPage:function(_options){
				var config = {
					href:'/'+sysmanMain.getRootPath()+'/antiMedical/query/popPage.action',
					window:$('#' + window_id),
					width:'900',
					height:'700',
					flag:false,
					onClose:private_method.closePage
				}
				
				//根据传递的patient_type判断数据类型
				if(_options.patient_type){
					switch(_options.patient_type){
						case '1':
						config.title = '门诊抗菌药物使用率';
						break;
						case '2':
						config.title = '住院抗菌药物使用率';
						break;
						case '3':
						config.title = '急诊抗菌药物使用率';
						break;
					}				
				}
					
				
				queryParam = _options
				sysmanMain.setModuConf(module_code,{initQueryParams:{condition:_options}})
				var _param = $.extend({},config,_options)
				datagridServ.windowEditCenter(_param);
			},
			/**
			 * 
			 */
			initMain:function(_options){
				_buttonConfig = {
					'返回':private_method.changePanel
				}				
				private_method.bindBtnEvent();
			},
			/**
			 * 设置模块点击页面
			 * @param _options.record 列表选中行
			 * @param _options.grid 页面form对象
			 * @param _options.rootId 页面根节点
			 */
			clickCell:function(index,field,value){
				
				var _config = sysmanMain.getCurrentModuConfig()
				
				if(!value  || value<=0){
					_config.clickValue = 0
					sysmanMain.setCurrentModuConfig(_config)
					return 
				}else{
					_config.clickValue = 1
					sysmanMain.setCurrentModuConfig(_config)
				}
				var _param ={}
				if(field && (field!=='sumary_matter')){
					_param.issue = field					
				}
				_config.clickParam = _param				
				sysmanMain.setCurrentModuConfig(_config)				
			},
			
			/**
			 * 设置模块点击参数页面
			 * @param _options.record 列表选中行
			 * @param _options.grid 页面form对象
			 * @param _options.rootId 页面根节点
			 */
			clickRow:function(index,row){
				if(window.console){
					console.log('index:' + index)
					console.log('row.doct_depart_name:' + row.doct_depart_name)					
				}
				var _config = sysmanMain.getCurrentModuConfig()	
				
				//点击为0cell
				if(_config.clickValue <= 0){
					return 
				}
				var _param = {doct_depart_code:row.doct_depart_code}
				if (_config.clickParam){					
					$.extend(_config.clickParam,_param) 
				}else{
					_config.clickParam = _param
				}
				sysmanMain.setCurrentModuConfig(_config)
				
				var initQueryParams = {condition:_config.clickParam}				
				
				sysmanMain.setModuConf('module_code',{initQueryParams:initQueryParams})
				
				private_method.openPage();
			}
			,
			clickBizRow:function(index,row){
				if(window.console){
					console.info('biz row clicked...')
				}
				private_method.changePanel()
				
				var _param =$.extend({},queryParam,{dept_code:row.dept_code,data_type:'3'})
				
				private_method.initDetail(_param)
			}
			
		}
		
		var private_method = {
			/**初始化明细页
			 * @param
			 */
			initDetail:function(_options){
				//定位明细列表
				var _t =  $('#'+window_id + ' div.details-panel table.dg-list')
				//清空明细列表
				if(!_t.datagrid('options') || !_t.datagrid('options').url){
					//根据条件加载明细列表
					_t.datagrid({						
						url:'/'+sysmanMain.getRootPath()+'/antiMedical/query/getListDomain.action',
						queryParam:{condition:_options}
					})
				}else{
					_t.datagrid('load',{condition:_options})
				}
			},
			closePage:function(){
				$('#'+window_id).empty();
			},
			/**
			 * 
			 */
			changePanel:function(_options){
				
				
				var $listPanel = $('#' +window_id +'  div.list-panel' )
				var $detailsPanel = $('#' +window_id +' div.details-panel' )
				
				panelUtil.togglePanel({target:$listPanel})
				panelUtil.togglePanel({target:$detailsPanel})
			},
			//绑定按钮事件
			bindBtnEvent:function(){			
				
				var	btn = $('#' + window_id  +' a.function-btn')
				
				// 绑定按钮事件
				
				//判断按钮是否存在
				if(btn.length>0){
					$(btn).unbind('click');
					$(btn).bind('click', private_method.function_btn_listenner)	
				}			
			},
			// 功能按钮监听函数
			function_btn_listenner : function(e) {
				btnServ.applyButton({buttonEvt:e,buttonConfig:_buttonConfig})
			}
		}
		return public_method;
})